#ifndef		__COMMON_DEF_H__
#define		__COMMON_DEF_H__


#define		TRUE		1
#define		ON			1

#define		FALSE		0
#define		OFF			0


#define SCI_DEBUG		0xaa
#define SCI_EXT			0x66
#define SCI_BT			0xcc
#define SCI_GPS			0x33

#define BYTES2INT(x,y)		(int16_t)(((uint16_t)(x) << 8) | (uint16_t)(y))
#define BYTES2UINT(x,y)		(uint16_t)(((uint16_t)(x) << 8) | (uint16_t)(y))


#define BIT_SET(x,y)		x |= (y)		
#define BIT_CLEAR(x,y)  	x &= ~(y)


#define BT_POWER_OFF		{BIT_SET(P3DIR, BT_LDO_CE); BIT_CLEAR(P3SEL, BT_LDO_CE); BIT_CLEAR(P3OUT, BT_LDO_CE);}
#define GYRO_POWER_OFF		{BIT_SET(P4DIR, GYRO_LDO_CE); BIT_CLEAR(P4SEL, GYRO_LDO_CE); BIT_CLEAR(P4OUT, GYRO_LDO_CE);}
#define ACCEL_POWER_OFF		{BIT_SET(P4DIR, ACCEL_LDO_CE); BIT_CLEAR(P4SEL, ACCEL_LDO_CE); BIT_CLEAR(P4OUT, ACCEL_LDO_CE);}
#define RF_POWER_OFF		{BIT_SET(P4DIR, RF_LDO_CE); BIT_CLEAR(P4SEL, RF_LDO_CE); BIT_CLEAR(P4OUT, RF_LDO_CE);}
#define COMPASS_POWER_OFF	{BIT_SET(P2DIR, COMPASS_LDO_CE); BIT_CLEAR(P2SEL, COMPASS_LDO_CE); BIT_CLEAR(P2OUT, COMPASS_LDO_CE);}
#define GPS_POWER_OFF		{BIT_SET(P4DIR, GPS_LDO_CE); BIT_CLEAR(P4SEL, GPS_LDO_CE); BIT_CLEAR(P4OUT, GPS_LDO_CE);}





#define BT_POWER_ON			{BIT_SET(P3DIR, BT_LDO_CE); BIT_CLEAR(P3SEL,BT_LDO_CE); BIT_SET(P3OUT, BT_LDO_CE);}
#define GYRO_POWER_ON		{BIT_SET(P4DIR, GYRO_LDO_CE); BIT_CLEAR(P4SEL, GYRO_LDO_CE); BIT_SET(P4OUT, GYRO_LDO_CE);}
#define ACCEL_POWER_ON		{BIT_SET(P4DIR, ACCEL_LDO_CE); BIT_CLEAR(P4SEL, ACCEL_LDO_CE); BIT_SET(P4OUT, ACCEL_LDO_CE);}
#define RF_POWER_ON			{BIT_SET(P4DIR, RF_LDO_CE); BIT_CLEAR(P4SEL, RF_LDO_CE); BIT_SET(P4OUT, RF_LDO_CE);}
#define COMPASS_POWER_ON	{BIT_SET(P2DIR, COMPASS_LDO_CE); BIT_CLEAR(P2SEL, COMPASS_LDO_CE); BIT_SET(P2OUT, COMPASS_LDO_CE);}
#define GPS_POWER_ON		{BIT_SET(P4DIR, GPS_LDO_CE); BIT_CLEAR(P4SEL, GPS_LDO_CE); BIT_SET(P4OUT, GPS_LDO_CE);}

#define GPS_ACTIVE			{BIT_SET(P4DIR, GPS_EN); BIT_CLEAR(P4SEL, GPS_EN); BIT_SET(P4OUT, GPS_EN);}
#define GPS_SLEEP			{BIT_SET(P4DIR, GPS_EN); BIT_CLEAR(P4SEL, GPS_EN); BIT_CLEAR(P4OUT, GPS_EN);}


#define ACCEL_SLEEP		{BIT_SET(P4DIR, ACCEL_SEP); BIT_CLEAR(P4SEL, ACCEL_SEP); BIT_CLEAR(P4OUT, ACCEL_SEP);}
#define ACCEL_ACTIVE	{BIT_SET(P4DIR, ACCEL_SEP); BIT_CLEAR(P4SEL, ACCEL_SEP); BIT_SET(P4OUT, ACCEL_SEP);}

#define ACCEL_G_SEL15		{BIT_SET(P4DIR, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_CLEAR(P4SEL, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_CLEAR(P4OUT, ACCEL_GSEL1 | ACCEL_GSEL2);}//1.5g
#define ACCEL_G_SEL20		{BIT_SET(P4DIR, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_CLEAR(P4SEL, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_SET(P4OUT, ACCEL_GSEL1); BIT_CLEAR(P4OUT, ACCEL_GSEL2);}//2g
#define ACCEL_G_SEL40		{BIT_SET(P4DIR, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_CLEAR(P4SEL, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_CLEAR(P4OUT, ACCEL_GSEL1); BIT_SET(P4OUT, ACCEL_GSEL2);}//4g
#define ACCEL_G_SEL60		{BIT_SET(P4DIR, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_CLEAR(P4SEL, ACCEL_GSEL1 | ACCEL_GSEL2); BIT_SET(P4OUT, ACCEL_GSEL1 | ACCEL_GSEL2);}//6g



#endif


//EOF===========
